package cn.com.dycc.party_org.member.service;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.regex.Pattern;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.com.dycc.common.attach.dao.AttachDao;
import cn.com.dycc.common.attach.entity.Attach;
import cn.com.dycc.common.entity.Pb_Integral_LogCount;
import cn.com.dycc.common.log.Constants;
import cn.com.dycc.common.log.SystemServiceLog;
import cn.com.dycc.party_org.member.dao.MemberDao;
import cn.com.dycc.party_org.member.entity.AllInfo;
import cn.com.dycc.party_org.member.entity.CountMember;
import cn.com.dycc.party_org.member.entity.Member;
import cn.com.dycc.party_org.member.entity.UserAndMember;
import cn.com.dycc.party_org.member.entity.UserChildAndMember;
import cn.com.dycc.party_org.member.param.FindMemberParam;
import cn.com.dycc.party_org.member.param.MemberParam;
import cn.com.dycc.party_org.organize.dao.OrganizeDao;
import cn.com.dycc.party_org.team.dao.TeamDao;
import cn.com.dycc.party_org.team.param.AddTeamParam;
import cn.com.dycc.party_work.education.dao.EducationDao;
import cn.com.dycc.party_work.education.entity.EducationFlag;
import cn.com.dycc.study_manage.integral.dao.Pb_Integral_LogDao;
import cn.com.dycc.study_manage.integral.param.Pb_Integral_LogParam;
import cn.com.dycc.sys_manage.usersysmanagement.dao.UserDao;
import cn.com.dycc.topic_activity.dao.Pb_Special_ActivityDao;
import cn.com.dycc.topic_activity.param.Pb_Special_ActivityParam;
import cn.com.dycc.util.DateUtil;
import cn.com.dycc.util.FileUtil;
import cn.com.dycc.util.IntegerUtil;
import cn.com.dycc.util.Paging;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**
 * 
 * Description: 党员业务层实现
 * Author: Liket
 * Version: 1.0
 * Create Date Time: 2018年6月22日 上午10:16:03.
 * Update Date Time: 
 * @see
 */
@Service("memberService")
public class MemberServiceImpl implements MemberService{
	
	@Resource
	private MemberDao memberDao;
	
	@Resource
	private TeamDao teamDao;
	
	@Resource(name="paging")
	private Paging paging;
	
	@Resource
	private AttachDao attachDao;
	
	@Resource
	private UserDao userDao;
	
	@Resource
	private OrganizeDao organizeDao;
	
	@Resource
	private Pb_Special_ActivityDao pb_Special_ActivityDao;
	
	@Resource
	private Pb_Integral_LogDao pb_Integral_LogDao;
	
	
	@Resource
	private EducationDao educationDao;
	
	@SystemServiceLog(description=Constants.ADDMEMBER)
	@Transactional
	public int addMember(MemberParam member,HttpServletRequest req) throws MemberNotFoundException {
		String certificateReg = "(^\\d{15}$)|(^\\d{18}$)|(^\\d{17}(\\d|X|x)$)";
		
		if(member==null){
			throw new MemberNotFoundException("请填写党员资料！");
		}
		HttpSession session = req.getSession();
		String user_id = (String) session.getAttribute("id");
		String org_id = (String)session.getAttribute("org_id");
		if(user_id==null){
			throw new MemberNotFoundException("请重新登录！");
		}
		
		MemberParam param = new MemberParam();
		param.setUser_id(user_id);
		param.setOrg_id(org_id);
		Member me = memberDao.findMember(param);
		if(me!=null){
			throw new MemberNotFoundException("该成员已经是党员，不能重复添加");
		}
		if(member.getUser_pic()==null||member.getUser_pic().trim().isEmpty()){
			throw new MemberNotFoundException("请上传头像");
		}
		if(member.getUser_id()==null||member.getUser_id().trim().isEmpty()){
			throw new MemberNotFoundException("请填写党员！");
		}
		if(member.getDept_id()==null||member.getDept_id().trim().isEmpty()){
			throw new MemberNotFoundException("请填写党组织！");
		}
		if(member.getParty_flag()==null||member.getParty_flag().trim().isEmpty()){
			throw new MemberNotFoundException("请填写党员标识！");
		}
		if(member.getParty_type()==null||member.getParty_type().trim().isEmpty()){
			throw new MemberNotFoundException("请填写党籍类别！");
		}
		if(member.getDj_flag()==null||member.getDj_flag().trim().isEmpty()){
			throw new MemberNotFoundException("请填写党籍标识！");
		}
		if(member.getApply_date()==null||member.getApply_date().trim().isEmpty()){
			throw new MemberNotFoundException("请填申请入党日期！");
		}
		if(member.getJoin_date()==null||member.getJoin_date().trim().isEmpty()){
			throw new MemberNotFoundException("请填写加入党组织日期！");
		}
		if(member.getParty_date()==null||member.getParty_date().trim().isEmpty()){
			throw new MemberNotFoundException("请填写正式入党日期！");
		}
		if(member.getCertificate()==null||member.getCertificate().trim().isEmpty()){
			throw new MemberNotFoundException("请填写身份证！");
		}		
			
		//System.out.println(member.getCertificate());
		if(!(Pattern.matches(certificateReg,member.getCertificate()))){
			throw new MemberNotFoundException("请填写正确的身份证号码！");
		}		
		
		if(member.getSex()==null||member.getSex().trim().isEmpty()){
			throw new MemberNotFoundException("请填写性别！");
		}
		
		if(member.getNative_place()==null||member.getNative_place().trim().isEmpty()){
			throw new MemberNotFoundException("请填写籍贯！");
		}
		
		if(member.getNation()==null||member.getNation().trim().isEmpty()){
			throw new MemberNotFoundException("请填写民族信息！");
		}
		
		if(member.getHealth()==null||member.getHealth().trim().isEmpty()){
			throw new MemberNotFoundException("请填写健康状态！");
		}		
		
		if(member.getEducation()==null||member.getEducation().trim().isEmpty()){
			throw new MemberNotFoundException("请填写学历！");
		}		
		
		if(member.getSponsor()==null||member.getSponsor().trim().isEmpty()){
			throw new MemberNotFoundException("请填写介绍人！");
		}
		
		if(member.getPropose()==null||member.getPropose().trim().isEmpty()){
			throw new MemberNotFoundException("请填写介绍人意见！");
		}
		
		if(member.getAddress()==null||member.getAddress().trim().isEmpty()){
			throw new MemberNotFoundException("请填写地址！");
		}	
		
		
		if(member.getBirthday()==null||member.getBirthday().trim().isEmpty()){
			throw new MemberNotFoundException("请填写出生日期！");
		}
		
		if(member.getClass_id()==null||member.getClass_id().trim().isEmpty()){
			throw new MemberNotFoundException("请填写职务！");
		}
		
		if(member.getPost_id()==null||member.getPost_id().trim().isEmpty()){
			throw new MemberNotFoundException("请填写岗位！");
		}
		
		if(member.getTel()==null||member.getTel().trim().isEmpty()){
			throw new MemberNotFoundException("请填写固定电话！");
		}
		if(!(IntegerUtil.isPhone(member.getTel().trim()))){
			throw new MemberNotFoundException("请填写正确的固定电话！");
		}
		
		if(member.getTel_m()==null||member.getTel_m().trim().isEmpty()){
			throw new MemberNotFoundException("请填写移动电话！");
		}
		if(!(IntegerUtil.isMobile(member.getTel_m().trim()))){
			throw new MemberNotFoundException("请填写正确的移动电话！");
		}
		
		
		member.setCreate_date(new Timestamp(new Date().getTime()));
		
		
		member.setOpt_user_id(user_id);
		member.setOrg_id((String)session.getAttribute("org_id"));
		
		member.setUpdate_date(DateUtil.getNowDate(DateUtil.TIME_FMT));
		member.setUpdate_user_id(user_id);
		
		/**
		 * 移动头像
		 */
		
		System.out.println(member.getUser_pic());
		
		String newPath = FileUtil.moveImage(member.getUser_pic(), "party_org");
		member.setUser_pic(newPath);
		
		int n = memberDao.addMember(member);		
		
		if(n<=0){
			throw new MemberNotFoundException("添加失败");
		}
		
		List<Attach> listAttach = new ArrayList<Attach>();
		
		if(member.getListAttach()!=null&&!member.getListAttach().trim().isEmpty()){
			String str=member.getListAttach().trim();
			//System.out.println(str);
			JSONArray json=JSONArray.fromObject(str);
			//System.out.println("l="+listAttach.size());
        
			for(int i=0;i<json.size();i++){

				//System.out.println("打桩2："+json.get(i));
				Object check=json.get(i);
				if("null".equals(check.toString())){
					continue;
				}
				JSONObject job = json.getJSONObject(i); // 遍历 jsonarray 数组，把每一个对象转成 json 对象
				
	
				String attach_ext=(String)job.get("attach_ext");
				String attach_path=(String)job.get("attach_path");
				String attach_size=(String)job.get("attach_size");
				String title=(String)job.get("title");
				Attach attach=new Attach();
				attach.setMessage_no(member.getUser_id());
				attach.setAttach_type(2);
				attach.setTitle(title);
				attach.setAttach_ext(attach_ext);
				attach.setAttach_path(attach_path);
				attach.setAttach_size(attach_size);				
				attach.setOrg_id((String)session.getAttribute("org_id"));
				attach.setOpt_user_id(user_id);
				listAttach.add(attach);
								
			}        
        }
        //System.out.println(listAttach);
		List<Attach> newListAttach=FileUtil.moveFile(listAttach,"party_org");
			
		//System.out.println("ATTACH"+newListAttach);
		if(newListAttach!=null){
		for(Attach attach:newListAttach){
			attachDao.insertAttach(attach);
				
			}
		}
		return n;
	}

	@Transactional
	@SystemServiceLog(description=Constants.DELETEMEMBER)
	public int deleteMember(String user_id, HttpServletRequest req) throws MemberNotFoundException {
		if(user_id==null||user_id.trim().isEmpty()){
			throw new MemberNotFoundException("选择要删除的党员");
		}
		HttpSession session = req.getSession();
		String org_id = (String) session.getAttribute("org_id");
		if(org_id==null){
			throw new MemberNotFoundException("重新登录");
		}
		AddTeamParam team = teamDao.findTeamByUserId(user_id);
		if(team!=null){
			throw new MemberNotFoundException("该党员属于党组班子成员，不能删除！");
		}
		Member member =new Member();
		member.setUser_id(user_id);
		member.setOrg_id(org_id);
		int n = memberDao.deleteMember(member);
		if(n!=1){
			throw new MemberNotFoundException("删除失败");
		}
		return n;
	}

	@Transactional
	@SystemServiceLog(description=Constants.DELETEMEMBER)
	public int deleteAllMember(String[] user_ids, HttpServletRequest req) throws MemberNotFoundException {
		if(user_ids==null){
			throw new MemberNotFoundException("选择要删除的党员");
		}
		if(user_ids.length<=0){
			throw new MemberNotFoundException("没有要删除的党员");
		}
		HttpSession session = req.getSession();
		String user_id2 = (String) session.getAttribute("id");
		if(user_id2==null){
			throw new MemberNotFoundException("重新登录");
		}
		AddTeamParam team = null;
		for(String user_id:user_ids){
			team = teamDao.findTeamByUserId(user_id);
			if(team!=null){
				throw new MemberNotFoundException("该党员属于党组班子成员，不能删除！");
			}
		}
		
		int n = memberDao.deleteAllMember(user_ids);
		if(n<=0){
			throw new MemberNotFoundException("删除失败");
		}
		return n;
	}

	@SystemServiceLog(description=Constants.UPDATEMEMBER)
	public int updateMember(MemberParam member, HttpServletRequest req) throws MemberNotFoundException {
		String certificateReg = "(^\\d{15}$)|(^\\d{18}$)|(^\\d{17}(\\d|X|x)$)";
		if(member==null){
			throw new MemberNotFoundException("请填写党员资料！");
		}
		if(member.getUser_pic()==null||member.getUser_pic().trim().isEmpty()){
			throw new MemberNotFoundException("请上传头像");
		}
		if(member.getUser_id()==null||member.getUser_id().trim().isEmpty()){
			throw new MemberNotFoundException("请填写党员！");
		}
		if(member.getDept_id()==null||member.getDept_id().trim().isEmpty()){
			throw new MemberNotFoundException("请填写党组织！");
		}
		if(member.getParty_flag()==null||member.getParty_flag().trim().isEmpty()){
			throw new MemberNotFoundException("请填写党员标识！");
		}
		if(member.getParty_type()==null||member.getParty_type().trim().isEmpty()){
			throw new MemberNotFoundException("请填写党籍类别！");
		}
		if(member.getDj_flag()==null||member.getDj_flag().trim().isEmpty()){
			throw new MemberNotFoundException("请填写党籍标识！");
		}
		if(member.getApply_date()==null||member.getApply_date().trim().isEmpty()){
			throw new MemberNotFoundException("请填申请入党日期！");
		}
		if(member.getJoin_date()==null||member.getJoin_date().trim().isEmpty()){
			throw new MemberNotFoundException("请填写加入党组织日期！");
		}
		if(member.getParty_date()==null||member.getParty_date().trim().isEmpty()){
			throw new MemberNotFoundException("请填写正式入党日期！");
		}
		if(member.getCertificate()==null||member.getCertificate().trim().isEmpty()){
			throw new MemberNotFoundException("请填写身份证！");
		}		
			
		if(!Pattern.matches(certificateReg,member.getCertificate())){
			throw new MemberNotFoundException("请填写正确的身份证号码！");
		}		
		
		if(member.getSex()==null||member.getSex().trim().isEmpty()){
			throw new MemberNotFoundException("请填写性别！");
		}
		
		if(member.getNation()==null||member.getNation().trim().isEmpty()){
			throw new MemberNotFoundException("请填写民族信息！");
		}
		
		if(member.getHealth()==null||member.getHealth().trim().isEmpty()){
			throw new MemberNotFoundException("请填写健康状态！");
		}
		
		if(member.getNative_place()==null||member.getNative_place().trim().isEmpty()){
			throw new MemberNotFoundException("请填写籍贯！");
		}
		
		if(member.getEducation()==null||member.getEducation().trim().isEmpty()){
			throw new MemberNotFoundException("请填写学历！");
		}		
		
		if(member.getSponsor()==null||member.getSponsor().trim().isEmpty()){
			throw new MemberNotFoundException("请填写介绍人！");
		}
		
		if(member.getPropose()==null||member.getPropose().trim().isEmpty()){
			throw new MemberNotFoundException("请填写介绍人意见！");
		}
		
		if(member.getAddress()==null||member.getAddress().trim().isEmpty()){
			throw new MemberNotFoundException("请填写地址！");
		}
		
		if(member.getBirthday()==null||member.getBirthday().trim().isEmpty()){
			throw new MemberNotFoundException("请填写出生日期！");
		}
		
		if(member.getClass_id()==null||member.getClass_id().trim().isEmpty()){
			throw new MemberNotFoundException("请填写职务！");
		}
		
		if(member.getPost_id()==null||member.getPost_id().trim().isEmpty()){
			throw new MemberNotFoundException("请填写岗位！");
		}
		
		if(member.getTel()==null||member.getTel().trim().isEmpty()){
			throw new MemberNotFoundException("请填写固定电话！");
		}
		if(!(IntegerUtil.isPhone(member.getTel().trim()))){
			throw new MemberNotFoundException("请填写正确的固定电话！");
		}
		
		if(member.getTel_m()==null||member.getTel_m().trim().isEmpty()){
			throw new MemberNotFoundException("请填写移动电话！");
		}
		if(!(IntegerUtil.isMobile(member.getTel_m().trim()))){
			throw new MemberNotFoundException("请填写正确的移动电话！");
		}
		
		
		HttpSession session = req.getSession();
		String user_id = (String) session.getAttribute("id");
		String org_id = (String) session.getAttribute("org_id");
		if(user_id==null){
			throw new MemberNotFoundException("请重新登录！");
		}
		MemberParam param = new MemberParam();
		param.setUser_id(user_id);
		param.setOrg_id(org_id);
		Member oldMember = memberDao.findMember(param);
		System.out.println(oldMember);
		if(oldMember==null){
			throw new MemberNotFoundException("此党员不存在");
		}
		
		
		
		//对比之后设置修改参数
		Member newMember = new Member();
		newMember.setUser_id(member.getUser_id());
		
		if(!member.getUser_pic().equals(oldMember.getUser_pic())){
			newMember.setUser_pic(member.getUser_pic());
		}
		
		if(!member.getNation().equals(oldMember.getNation())){
			newMember.setNation(member.getNation());
		}
		
		if(!member.getHealth().equals(oldMember.getHealth())){
			newMember.setHealth(member.getHealth());
		}
		
		if(!member.getDept_id().equals(oldMember.getDept_id())){
			newMember.setDept_id(member.getDept_id());
		}
		if(!member.getCertificate().equals(oldMember.getCertificate())){
			newMember.setCertificate(member.getCertificate());
		}
		
		if(!member.getSex().equals(oldMember.getSex())){
			newMember.setSex(member.getSex());
		}
		if(!member.getNative_place().equals(oldMember.getNative_place())){
			newMember.setNative_place(member.getNative_place());
		}
		if(!member.getEducation().equals(oldMember.getEducation())){
			newMember.setEducation(member.getEducation());
		}
		if(!member.getParty_flag().equals(oldMember.getParty_flag())){
			newMember.setParty_flag(member.getParty_flag());
		}
		if(!member.getParty_type().equals(oldMember.getParty_type())){
			newMember.setParty_type(member.getParty_type());
		}
		if(!member.getDj_flag().equals(oldMember.getDj_flag())){
			newMember.setDj_flag(member.getDj_flag());
		}
		if(!member.getApply_date().equals(oldMember.getApply_date())){
			newMember.setApply_date(member.getApply_date());
		}
		if(!member.getJoin_date().equals(oldMember.getJoin_date())){
			newMember.setJoin_date(member.getJoin_date());
		}
		if(!member.getParty_date().equals(oldMember.getParty_date())){
			newMember.setParty_date(member.getParty_date());
		}
		if(!member.getSponsor().equals(oldMember.getSponsor())){
			newMember.setSponsor(member.getSponsor());
		}
		
		if(!member.getPropose().equals(oldMember.getPropose())){
			newMember.setPropose(member.getPropose());
		}
		
		if(!member.getAddress().equals(oldMember.getAddress())){
			newMember.setAddress(member.getAddress());
		}
		if(!member.getBirthday().equals(oldMember.getBirthday())){
			newMember.setBirthday(member.getBirthday());
		}
		if(!member.getClass_id().equals(oldMember.getClass_id())){
			newMember.setClass_id(member.getClass_id());
		}
		if(!member.getPost_id().equals(oldMember.getPost_id())){
			newMember.setPost_id(member.getPost_id());
		}
		if(!member.getTel().equals(oldMember.getTel())){
			newMember.setTel(member.getTel());
		}
		if(!member.getTel_m().equals(oldMember.getTel_m())){
			newMember.setTel_m(member.getTel_m());
		}
		
		if(!user_id.equals(oldMember.getOpt_user_id())){
			newMember.setOpt_user_id(user_id);;
		}
		if(member.getRemark()!=null){
			newMember.setRemark(member.getRemark());
		}
		if(member.getState()!=null){
			newMember.setState(member.getState());
		}
		newMember.setUpdate_date(DateUtil.getNowDate(DateUtil.TIME_FMT));
		newMember.setOrg_id(org_id);
		int n = memberDao.updateMember(newMember);		
		if(n!=1){
			throw new MemberNotFoundException("修改失败");
		}
		
		//附件
		List<Attach> listAttach = new ArrayList<Attach>();
		
		if(member.getListAttach()!=null&&!member.getListAttach().trim().isEmpty()){
			String str=member.getListAttach().trim();
			//System.out.println(str);
			JSONArray json=JSONArray.fromObject(str);
			//System.out.println("l="+listAttach.size());
        
			for(int i=0;i<json.size();i++){

				//System.out.println("打桩2："+json.get(i));
				Object check=json.get(i);
				if("null".equals(check.toString())){
					continue;
				}
				JSONObject job = json.getJSONObject(i); // 遍历 jsonarray 数组，把每一个对象转成 json 对象
				
	
				String attach_ext=(String)job.get("attach_ext");
				String attach_path=(String)job.get("attach_path");
				String attach_size=(String)job.get("attach_size");
				String title=(String)job.get("title");
				Attach attach=new Attach();
				attach.setMessage_no(member.getUser_id());
				attach.setAttach_type(2);
				attach.setTitle(title);
				attach.setAttach_ext(attach_ext);
				attach.setAttach_path(attach_path);
				attach.setAttach_size(attach_size);				
				attach.setOrg_id((String) session.getAttribute("org_id"));
				attach.setOpt_user_id(user_id);
				listAttach.add(attach);
								
			}        
        }
        //System.out.println(listAttach);
		List<Attach> newListAttach=FileUtil.moveFile(listAttach,"party_org");
			
		//System.out.println("ATTACH"+newListAttach);
		if(newListAttach!=null){
		for(Attach attach:newListAttach){
			attachDao.insertAttach(attach);
				
			}
		}
		return n;
	}

	public Member findMember(String user_id, HttpServletRequest req) throws MemberNotFoundException {
		if(user_id==null||user_id.trim().isEmpty()){
			throw new MemberNotFoundException("选择查询的党员");
		}
		HttpSession session = req.getSession();
		String org_id = (String) session.getAttribute("org_id");
		if(org_id==null){
			throw new MemberNotFoundException("重新登录");
		}
		MemberParam param = new MemberParam();
		param.setUser_id(user_id);
		param.setOrg_id(org_id);
		Member member = memberDao.findMember(param);
		if(member==null){
			throw new MemberNotFoundException("此党员不存在");
		}
		return member;
	}

	public List<UserChildAndMember> findAllMemberByParam(FindMemberParam param,HttpServletRequest req) throws MemberNotFoundException {
		
		HttpSession session = req.getSession();		
		String org_id = (String) session.getAttribute("org_id");
		if(org_id==null){
			throw new MemberNotFoundException("重新登录");
		}
		Integer page = param.getPage();
		Integer limit = param.getLimit();
		Integer start = null;
		if(limit==null&&page!=null){
			limit = paging.getPageSize();
			start=(page-1)*limit;
		}
		if(page==null){
			start = null;
			limit = null;
		}
		if(limit!=null&&page!=null){
			start = limit*(page-1);
		}		
		param.setStart(start);	
		param.setOrg_id(org_id);
		System.out.println("param:"+param);
		List<UserChildAndMember> list = memberDao.findAllMemberByParam(param);
		
		/*if(list==null){
			throw new ApplyNotFoundException("查询失败");
		}*/
		
		return list;
	}
	
	public List<UserAndMember> findAllMember(FindMemberParam param,HttpServletRequest req) throws MemberNotFoundException {
		
		HttpSession session = req.getSession();		
		String org_id = (String) session.getAttribute("org_id");
		if(org_id==null){
			throw new MemberNotFoundException("重新登录");
		}
		Integer page = param.getPage();
		Integer limit = param.getLimit();
		Integer start = null;
		if(limit==null&&page!=null){
			limit = paging.getPageSize();
			start=(page-1)*limit;
		}
		if(page==null){
			start = null;
			limit = null;
		}
		if(limit!=null&&page!=null){
			start = limit*(page-1);
		}		
		param.setStart(start);	
		param.setOrg_id(org_id);
		List<UserAndMember> list = memberDao.findAllMember(param);
		
		/*if(list==null){
			throw new ApplyNotFoundException("查询失败");
		}*/
		
		return list;
	}

	public String findAllMemberCount(FindMemberParam param,HttpServletRequest req) throws MemberNotFoundException {
		
		HttpSession session = req.getSession();		
		String org_id = (String) session.getAttribute("org_id");
		if(org_id==null){
			throw new MemberNotFoundException("重新登录");
		}
		param.setOrg_id(org_id);
		String n = memberDao.findAllMemberCount(param);		
		return n;
	}
	
	public String findAllMemberCountByParam(FindMemberParam param,HttpServletRequest req) throws MemberNotFoundException {
		
		HttpSession session = req.getSession();		
		String org_id = (String) session.getAttribute("org_id");
		if(org_id==null){
			throw new MemberNotFoundException("重新登录");
		}
		param.setOrg_id(org_id);
		String n = memberDao.findAllMemberCountByParam(param);		
		return n;
	}

	public UserChildAndMember findMemberByUserId(String user_id, HttpServletRequest req) throws MemberNotFoundException {
		if(user_id==null||user_id.trim().isEmpty()){
			throw new MemberNotFoundException("选择查询的党员");
		}
		HttpSession session = req.getSession();
		//判断session值是否存在
		String org_id = (String) session.getAttribute("org_id");
		if(org_id==null){
			throw new MemberNotFoundException("重新登录");
		}
		MemberParam param = new MemberParam();
		param.setUser_id(user_id);
		param.setOrg_id(org_id);
		UserChildAndMember member = memberDao.findMemberByUserId(param);
		if(member==null){
			throw new MemberNotFoundException("此党员不存在");
		}
		return member;
	}

	public CountMember countMember(HttpServletRequest req) throws MemberNotFoundException {
		HttpSession session = req.getSession();
		//判断session值是否存在
		String org_id = (String) session.getAttribute("org_id");
		if(org_id==null){
			throw new MemberNotFoundException("重新登录");
		}
		
		String countMonth = memberDao.countMonth(org_id);
		String countAll = memberDao.countAll(org_id);
		CountMember cm = new CountMember();
		cm.setCountAll(countAll);
		cm.setCountMonth(countMonth);
		
		return cm;
	}

	public AllInfo allInfoCount(HttpServletRequest req) throws MemberNotFoundException {
		HttpSession session = req.getSession();
		//判断session值是否存在
		String org_id = (String) session.getAttribute("org_id");
		if(org_id==null){
			throw new MemberNotFoundException("重新登录");
		}
		AllInfo info = new AllInfo();
		String userCount = userDao.userCount(org_id);
		String memberCount = memberDao.countAll(org_id);
		String deptCount = organizeDao.deptPartyCount(org_id);
		Pb_Special_ActivityParam para = new Pb_Special_ActivityParam();
		para.setOrg_id(org_id);
		String activityCount = pb_Special_ActivityDao.getPb_Special_ActivityCountByParam(para);
		EducationFlag flagInfo = educationDao.countFlag(org_id);
		String shyk = "";
		String lxyz = "";
		if(flagInfo!=null){
			shyk = flagInfo.getShyk();
			lxyz = flagInfo.getLxyz();
		}
		info.setUserCount(userCount);
		info.setMemberCount(memberCount);
		info.setDeptCount(deptCount);
		info.setActivityCount(activityCount);
		info.setShykCount(shyk);
		info.setLxyzCount(lxyz);		
		
		return info;
	}

	public List<Pb_Integral_LogCount> countMemberByIntegral(HttpServletRequest req,Pb_Integral_LogParam param) throws MemberNotFoundException {
		HttpSession session = req.getSession();
		//判断session值是否存在
		//String user_id = (String) session.getAttribute("id");
		if(session==null||session.getAttribute("id")==null){
			throw new MemberNotFoundException("重新登录");
		}
		String org_id = (String) session.getAttribute("org_id");
		param.setOrg_id(org_id);
		List<Pb_Integral_LogCount> list =  pb_Integral_LogDao.indexIntegralCount(param);
		System.out.println(list);
		return list;
	}

	

}
